package ${package.Controller};

<#assign thisName="${table.comment!}"/>
<#assign thisEntity="${entity?uncap_first}"/>
<#assign thisDTO="${entity}DTO"/>
<#assign thisQuery="${entity}Query"/>
<#assign thisVO="${entity}VO"/>
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import xin.nick.constant.SystemConstants;
import ${package.Service}.${entity}Service;
import ${package.Parent}.domain.dto.${entity}UpdateDTO;
import ${package.Parent}.domain.dto.${entity}CreateDTO;
import ${package.Parent}.domain.query.${thisQuery};
import ${package.Parent}.domain.vo.${thisVO};
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

import java.util.List;

/**
 * <p>
 * ${thisName} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Tag(name = "${thisName}模块")
@RequiredArgsConstructor
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("/api<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    <#assign thisService="${entity?uncap_first}Service"/>
    private final ${entity}Service ${thisService};

    @Operation(summary = "${thisName}详情",
            security = { @SecurityRequirement(name = SystemConstants.HEADER_AUTHORIZATION) })
    @GetMapping("/getDetail/{id}")
    @PreAuthorize("@webSecurity.check('${thisEntity}:detail')")
    public ${thisVO} getDetail(@PathVariable(name = "id") Long id) {
        return ${thisService}.getDetail(id);
    }

    @Operation(summary = "${thisName}列表",
            security = { @SecurityRequirement(name = SystemConstants.HEADER_AUTHORIZATION) })
    @GetMapping("/getList")
    @PreAuthorize("@webSecurity.check('${thisEntity}:list')")
    public List<${thisVO}> getList(${thisQuery} query) {
        return ${thisService}.getList(query);
    }

    @Operation(summary = "${thisName}列表分页",
            security = { @SecurityRequirement(name = SystemConstants.HEADER_AUTHORIZATION) })
    @GetMapping("/getListPage")
    @PreAuthorize("@webSecurity.check('${thisEntity}:list')")
    public Page<${thisVO}> getListPage(${thisQuery} query) {
        return ${thisService}.getListPage(query);
    }

    @Operation(summary = "${thisName}创建",
            security = { @SecurityRequirement(name = SystemConstants.HEADER_AUTHORIZATION) })
    @PostMapping("/create")
    @PreAuthorize("@webSecurity.check('${thisEntity}:add')")
    public ${thisVO} create(@RequestBody @Valid ${entity}CreateDTO dto) {
        return ${thisService}.create${entity}(dto);
    }

    @Operation(summary = "${thisName}更新",
            security = { @SecurityRequirement(name = SystemConstants.HEADER_AUTHORIZATION) })
    @PutMapping("/update")
    @PreAuthorize("@webSecurity.check('${thisEntity}:update')")
    public ${thisVO} update(@RequestBody @Valid ${entity}UpdateDTO dto) {
        return ${thisService}.update${entity}(dto);
    }

    @Operation(summary = "${thisName}删除",
            security = { @SecurityRequirement(name = SystemConstants.HEADER_AUTHORIZATION) })
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasRole('" + SystemConstants.ROOT + "') || hasAnyAuthority('${thisEntity}:delete')")
    public void delete(@PathVariable(name = "id") Long id) {
        ${thisService}.deleteById(id);
    }

    @Operation(summary = "${thisName}批量删除",
            security = { @SecurityRequirement(name = SystemConstants.HEADER_AUTHORIZATION) })
    @DeleteMapping("/deleteByIdList/{idList}")
    @PreAuthorize("@webSecurity.check('${thisEntity}:delete')")
    public void delete(@PathVariable(name = "idList") List<Long> idList) {
        ${thisService}.deleteByIdList(idList);
    }

}
</#if>
